package com.example.demo.juc;

import java.util.concurrent.CountDownLatch;

public class Test002 {

    static  volatile  int result = 0;
    static CountDownLatch countDownLatch = new CountDownLatch(4);

    static  class  MyThread implements  Runnable{

        int start;
        int end;

        public  MyThread(int start,int end){
            this.start = start;
            this.end = end;
        }

        @Override
        public void run() {
            countDownLatch.countDown();
            for (int i = start; i <= end ; i++) {
                result+=i;
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        for (int i = 0; i <=4 ; i++) {
            new Thread(new MyThread((i-1)*25+1,i*25)).start();
        }
        countDownLatch.await();
        System.out.println(result);
    }
}
